<?php

class Default_RssController extends Zend_Controller_Action
{

    public function init()
    {
        /* Initialize action controller here */
    }

    public function indexAction()
    {
    	$code = 'rss';
    	
    	$grandprixDAO = new Application_Model_GrandprixDAO();
        $grandprix = $grandprixDAO->findTop5();
    	
        $array = array('title' => "Wroom",
               'link' => 'http://localhost/wroom/public',
               'charset' => 'utf-8',
               'description' => "Les dernièrs résultats de Wroom",
               'author' => 'Pierre Fraisse',
               'email' => 'pierre.fraisse@etu.unilim.fr',
               'generator' => 'Zend Framework Zend_Feed',
               'language' => 'fr',
               'entries' => array());
    	
        //on ajoute des entrées
        
        foreach($grandprix as $gp)
        {
        	$course = $gp->getCourse();
        	if(count($course)!=0)
        	{
        		$pilote=$course[0]->getPilote();
        		$tempsCourse=$course[0]->getTempsCourse();
        		$gpNum=$course[0]->getGpNum();
        		$photos=$pilote->getPhotos();
        		$image = "<img src='".$this->view->url(array('path'=>urlencode($this->view->serverUrl().$this->view->baseUrl()."/images/pilote/".$photos[0]->getPhoAdresse()),'width'=>84,'height'=>84),'thumb')."' alt='".$pilote->getPilPrenom()." ".$pilote->getPilNom()."'/>";
        		$array['entries'][] = array('title' => $gp->getGpNom(),
                                'link' => $this->view->serverUrl().$this->view->url(array('id'=>$gp->getGpNum()),'resultatshow'),
                                'description' => $image."<br />".substr(strip_tags($gp->getGpCommentaire()),0,256).
                                                 ((strlen($gp->getGpCommentaire())>256)?"...":""),
                                'content' => $image."<br />".$gp->getGpCommentaire(),
                                'lastUpdate' => strtotime($gp->getGpDateMaj()));
        	}
        }
        
    	$feed=Zend_Feed::importArray($array,$code);  
        
        $feed->send();
        $this->_helper->layout->disableLayout();
        $this->_helper->viewRenderer->setNoRender();
    }
}

